package com.example.administrator.newxlmedical;

import android.app.FragmentTransaction;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.baseproject.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import constants.Constants;
import constants.HandlerConstant;
import customhandler.MyHandler;
import fragments.FasterLoginFragment;
import fragments.PasswordLoginFragment;
//import pl.droidsonroids.gif.GifImageView;
import singleton.SingletonClass;
import utils.ToastUtil;

public class EnterActivity extends BaseActivity {

    //    @BindView(R.id.tv_enter_fingerprint_enter)
//    TextView tvFingerprint;
//    @BindView(R.id.tv_enter_iris_enter)
//    TextView tvIris;
    @BindView(R.id.ll_enter)
    LinearLayout llEnter;
    @BindView(R.id.ll_enter_log)
    LinearLayout llEnterLog;
    @BindView(R.id.tv_enter_version)
    TextView tvVersion;
    @BindView(R.id.tv_enter_switch)
    TextView tvEnterSwitch;
    private MyHandler allHandler;
    private int count;
    private int count_log;
    private boolean isPassword;
    private boolean isFrist;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_enter);
        ButterKnife.bind(this);
        Constants.CHECK_LOG = false;
        allHandler = SingletonClass.getSingleton(MyHandler.class);
        // 重置 快捷开门 判断值
        Constants.IS_SHOW_FASTER_OPENDOOR = true;
        // 重置 快捷开门 语音 判断值
        Constants.IS_FRIST_OPENDOOR = true;
        PackageManager pm = getPackageManager();
        PackageInfo pi = null;
        try {
            pi = pm.getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        // versionName = pi.versionName;
        clickContent();
        tvVersion.setText("版本号：" + pi.versionName);
    }

    @OnClick({R.id.ll_enter, R.id.ll_enter_log, R.id.tv_enter_switch})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_enter:
                count++;
                if (count == 8) {
//                    allHandler.sendEmptyMessage(HandlerConstant.TEST);
                    finish();
                }
                break;
            case R.id.ll_enter_log:
                count_log++;
                if (count_log == 8) {
                    Constants.CHECK_LOG = true;
                    ToastUtil.showToast(EnterActivity.this, "log模式开启");
                }

                break;
            case R.id.tv_enter_switch:
                clickContent();
                break;

        }
    }

    private void clickContent() {
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        if (isFrist) {
            transaction.setCustomAnimations(
                    R.animator.enter_right_in,
                    R.animator.enter_left_out,
                    R.animator.enter_left_in,
                    R.animator.enter_right_out);
        }
        isFrist = true;
        if (isPassword) {
            transaction.replace(R.id.fl_enter_login, new PasswordLoginFragment());
            tvEnterSwitch.setText("快捷登录");
        } else {
            transaction.replace(R.id.fl_enter_login, new FasterLoginFragment());
            tvEnterSwitch.setText("密码登录");
        }
        transaction.commit();
        isPassword = !isPassword;
    }
}
